import Vue from 'vue'
import Router from 'vue-router'

// import HelloWorld from '@/components/HelloWorld'
// import About from "@/components/About"
// import User from "@/components/User"

// add by houlu  bug fix :
// Uncaught(in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/about" or "/home".
const originalPush = Router.prototype.push

Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const originalPush2 = Router.prototype.replace

Router.prototype.replace = function replace(location) {
  return originalPush2.call(this, location).catch(err => err)
}

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      redirect: '/home'
    },
    {
      path: '/home',
      name: 'HelloWorld',
      component: () => import('@/components/Home')
    },
    {
      path: '/about',
      name: 'About',
      component: () => import('@/components/About')
    },
    {
      path: '/user/:username',
      name: 'User',
      component:  () => import('@/components/User')
    }
  ],
  mode: 'history',
  linkActiveClass : 'router-link-active'
})
